//
//  SDPersonManager.m
//  SDDataTest
//
//  Created by sodao on 12-9-27.
//  Copyright (c) 2012年 sodao. All rights reserved.
//

#import "SDPersonManager.h"
#import "SDNetOperation.h"
#import "SDDataPool.h"

@implementation SDPersonManager
@synthesize personDataPool;
@synthesize userFans;
@synthesize userFav;
@synthesize userSug;
@synthesize user;


-(void)loginByAccount:(NSString*)account psd:(NSString*)psd otherInfo:(NSDictionary*)info{
    SBJsonWriter* writer = [[SBJsonWriter alloc] init];
    NSString* otherInfo = [writer stringWithObject:info];
    [writer release];
    [[SDNetOperation shareInstance] sendRequestByName:SDAPI_Login
                                             getParam:nil
                                            postParam:[NSDictionary dictionaryWithObjectsAndKeys:account,@"un",psd,@"p",otherInfo,@"statis", nil]
                                            restParam:nil
                                             postType:0
                                                token:nil
                                             deviceID:nil
                                        responseBlock:^(NSString *responseString) {
                                            id obj = [_jsonParser objectWithString:responseString];
                                            if (obj == nil) {
                                                
                                            }else{
                                                NSDictionary* dic = (NSDictionary*)obj;
                                                NSLog(dic.description);
                                                if ([[dic objectForKey:@"status"] intValue]==1) {
                                                    user.userID = [dic objectForKey:@"userId"];
                                                    user.nickName = [dic objectForKey:@"nickName"];
                                                    user.headerURL = [dic objectForKey:@"headerImage"];
                                                    [[SDDataPool shareInstance] setCurrentToken:[dic objectForKey:@"token"]];
                                                }else{
                                                    [[NSNotificationCenter defaultCenter] postNotificationName:NotifactionParaseResponseStringError object:nil];
                                                }
                                            }
                                        } failBlock:^(NSString *responseString, NSError *error) {
                                            NSLog(@"%@",responseString);
                                        }];

}

-(id)init{
    if (self=[super init]) {
        _jsonParser = [[SBJsonParser alloc] init];
    }
    return self;
}
-(void)dealloc{
    [super dealloc];
    [_jsonParser release];
}

@end
